package com.wffz.comm.api;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
/**
 * @Description: []
 * @Title: 
 * @Author: SUNLEI
 * @Date: 2023-04-21
 * @Param: null 
 * @Return: null
 * @Throws: 
 */
@Data
public class ResponseResult<T> implements Serializable {


    @ApiModelProperty("标记是否成功")
    private boolean success;
    @ApiModelProperty("是否将返回值包装为ResponseResult")
    private boolean decorate;
    @ApiModelProperty("错误码")
    private Integer code;
    @ApiModelProperty("错误信息")
    private String message;
    @ApiModelProperty("业务对象，继承自BaseEntity")
    private T data;
    @ApiModelProperty("跟踪ID")
    private String traceId;
    @ApiModelProperty("异常名称")
    private String exceptionName;


    public static <T> ResponseResult<T> success(T data) {
        ResponseResult r = new ResponseResult();
        r.setSuccess(true);
        r.setData(data);
        r.setCode(ResultCode.SUCCESS);
        r.setMessage("成功");
        return r;
    }

    public static <T> ResponseResult<T> error(T data) {
        ResponseResult r = new ResponseResult();
        r.setSuccess(false);
        r.setData(data);
        r.setCode(ResultCode.SUCCESS);
        return r;
    }


    public static ResponseResult error() {
        ResponseResult r = new ResponseResult();
        r.setSuccess(false);
        r.setCode(ResultCode.ERROR);
        r.setMessage("失败");
        return r;
    }


    public static <T> ResponseResult<T>  loginFail(T data){
        ResponseResult r = new ResponseResult();
        r.setSuccess(false);
        r.setCode(ResultCode.LOGIN_ERR);
        r.setData(data);
        r.setMessage("失败");
        return r;
    }
}
